home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / FROMUTS / CDUNGEON / !CDUNGEON / c / SUPP < prev    next >
Text File  |  1991-05-20  |  5KB  |  231 lines

  1. /* supp.c -- support routines for dungeon */
  2.  
  3. #include <stdio.h>
  4.  
  5. #ifdef unix
  6. #include <sys/types.h>
  7. #endif
  8.  
  9. #ifdef BSD4_2
  10. #include <sys/time.h>
  11. #else /* ! BSD4_2 */
  12. #include <time.h>
  13. #endif /* ! BSD4_2 */
  14.  
  15. #include "funcs.h"
  16.  
  17. /* Define these here to avoid using <stdlib.h> */
  18.  
  19. extern void exit P((int));
  20. extern int rand P((void));
  21.  
  22. /* We should have a definition for time_t and struct tm by now.  Make
  23.  * sure we have definitions for the functions we want to call.
  24.  * The argument to localtime should be P((const time_t *)), but Ultrix
  25.  * 4.0 leaves out the const in their prototype.  Damn them.
  26.  */
  27.  
  28. extern time_t time P((time_t *));
  29. extern struct tm *localtime ();
  30.  
  31. /* Terminate the game */
  32.  
  33. void exit_()
  34. {
  35.     fprintf(stderr, "The game is over.\n");
  36.     exit(0);
  37. }
  38.  
  39. /* Get time in hours, minutes and seconds */
  40.  
  41. void itime_(hrptr, minptr, secptr)
  42. integer *hrptr;
  43. integer *minptr;
  44. integer *secptr;
  45. {
  46.     time_t timebuf;
  47.     struct tm *tmptr;
  48.  
  49.     time(&timebuf);
  50.     tmptr = localtime(&timebuf);
  51.     
  52.     *hrptr  = tmptr->tm_hour;
  53.     *minptr = tmptr->tm_min;
  54.     *secptr = tmptr->tm_sec;
  55. }
  56.  
  57. /* Random number generator */
  58.  
  59. integer rnd_(maxval)
  60. integer maxval;
  61. {
  62.     return rand() % maxval;
  63. }
  64.  
  65. /* Terminal support routines for dungeon */
  66. /* By Ian Lance Taylor ian@airs.com or uunet!airs!ian */
  67.  
  68. /* The dungeon game can often output long strings, more than enough
  69.  * to overwhelm a typical 24 row terminal (I assume that back when
  70.  * dungeon was written people generally used paper terminals (I know
  71.  * I did) so this was not a problem).  The functions in this file
  72.  * provide a very simplistic ``more'' facility.  They are necessarily
  73.  * somewhat operating system dependent, although I have tried to
  74.  * minimize it as much as I could.
  75.  */
  76.  
  77. /* The following macro definitions may be used to control how these
  78.  * functions work:
  79.  *
  80.  *    MORE_NONE    Don't use the more facility at all
  81.  *    MORE_24        Always assume a 24 row terminal
  82.  *    MORE_TERMCAP    Use termcap routines to get rows of terminal
  83.  *    MORE_TERMINFO    Use terminfo routines to get rows of terminal
  84.  *    MORE_AMOS    Use AMOS monitor calls to get rows of terminal
  85.  *
  86.  * If none of these are defined then this will use termcap routines on
  87.  * unix and AMOS routines on AMOS.
  88.  */
  89.  
  90. #ifndef MORE_NONE
  91. #ifndef MORE_24
  92. #ifndef MORE_TERMCAP
  93. #ifndef MORE_TERMINFO
  94. #ifndef MORE_AMOS
  95. #ifdef __AMOS__
  96. #define MORE_AMOS
  97. #else /* ! __AMOS__ */
  98. #ifdef unix
  99. #define MORE_TERMCAP
  100. #else /* ! unix */
  101. #define MORE_NONE
  102. #endif /* ! unix */
  103. #endif /* ! __AMOS__ */
  104. #endif /* ! MORE_AMOS */
  105. #endif /* ! MORE_TERMINFO */
  106. #endif /* ! MORE_TERMCAP */
  107. #endif /* ! MORE_24 */
  108. #endif /* ! MORE_NONE */
  109.  
  110. #ifdef MORE_TERMCAP
  111.  
  112. extern char *getenv P((const char *));
  113. extern void tgetent P((char *, const char *));
  114. extern int tgetnum P((const char *));
  115.  
  116. #else /* ! MORE_TERMCAP */
  117.  
  118. #ifdef MORE_TERMINFO
  119.  
  120. #include <cursesX.h>
  121. #include <term.h>
  122. extern void setupterm P((const char *, int, int));
  123.  
  124. #else /* ! MORE_TERMINFO */
  125.  
  126. #ifdef MORE_AMOS
  127.  
  128. #include <moncal.h>
  129. #include <unistd.h>
  130.  
  131. #endif /* MORE_AMOS */
  132. #endif /* ! MORE_TERMINFO */
  133. #endif /* ! MORE_TERMCAP */
  134.  
  135. /* Initialize the more waiting facility (determine how many rows the
  136.  * terminal has).
  137.  */
  138.  
  139. static integer crows;
  140. static integer coutput;
  141.  
  142. void more_init()
  143. {
  144. #ifdef MORE_NONE
  145.  
  146.     crows = 0;
  147.  
  148. #else /* ! MORE_NONE */
  149. #ifdef MORE_24
  150.  
  151.     crows = 24;
  152.  
  153. #else /* ! MORE_24 */
  154. #ifdef MORE_TERMCAP
  155.  
  156.     char buf[2048];
  157.     char *term;
  158.  
  159.     term = getenv("TERM");
  160.     if (term == NULL)
  161.     crows = 0;
  162.     else {
  163.     tgetent(buf, term);
  164.     crows = tgetnum("li");
  165.     }
  166.  
  167. #else /* ! MORE_TERMCAP */
  168. #ifdef MORE_TERMINFO
  169.  
  170.     int i;
  171.  
  172.     setupterm(NULL, 1, &i);
  173.     if (i != 1)
  174.         crows = 0;
  175.     else
  176.     crows = lines;
  177.  
  178. #else /* ! MORE_TERMINFO */
  179. #ifdef MORE_AMOS
  180.  
  181.     trm_char st;
  182.  
  183.     if (isatty(fileno(stdin)) == 0)
  184.     crows = 0;
  185.     else {
  186.         trmchr(&st, 0);
  187.         crows = st.row;
  188.     }
  189.  
  190. #else /* ! MORE_AMOS */
  191.  
  192.     This should be impossible
  193.  
  194. #endif /* ! MORE_AMOS */
  195. #endif /* ! MORE_TERMINFO */
  196. #endif /* ! MORE_TERMCAP */
  197. #endif /* ! MORE_24 */
  198. #endif /* ! MORE_NONE */
  199. }
  200.  
  201. /* The program wants to output a line to the terminal.  If z is not
  202.  * NULL it is a simple string which is output here; otherwise it
  203.  * needs some sort of formatting, and is output after this function
  204.  * returns (if all computers had vprintf I would just it, but they
  205.  * probably don't).
  206.  */
  207.  
  208. void more_output(z)
  209. const char *z;
  210. {
  211.     if (crows > 0  &&  coutput > crows - 2) {
  212.     printf("Press return to continue: ");
  213.     (void) fflush(stdout);
  214.     while (getchar() != '\n')
  215.         ;
  216.     coutput = 0;
  217.     }
  218.  
  219.     if (z != NULL)
  220.     printf("%s\n", z);
  221.  
  222.     coutput++;
  223. }
  224.  
  225. /* The terminal is waiting for input (clear the number of output lines) */
  226.  
  227. void more_input()
  228. {
  229.     coutput = 0;
  230. }
  231.